package com.itheima.tlias.mapper;


import com.github.pagehelper.Page;
import com.itheima.tlias.pojo.AddStudentDTO;
import com.itheima.tlias.pojo.Student;
import com.itheima.tlias.pojo.StudentDTO;
import com.itheima.tlias.pojo.StudentVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 06 4月 2025 17:33
 */
@Mapper
public interface StudentMapper {
    /**
     * 分页查询
     *
     * @param studentDTO
     * @return
     */

    Page<StudentVo> pageQuery(StudentDTO studentDTO);


    /**
     * 根据班级id查询学生
     *
     * @param id
     * @return
     */

    @Select("select * from student where clazz_id = #{id}")
    List<StudentVo> selectByClazzId(Integer id);

    /**
     * 批量删除
     *
     * @param ids
     */
    void batchDelete(List<Integer> ids);

    /**
     * 添加学生
     *
     * @param addStudentDTO
     */
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, " +
            "degree, graduation_date, clazz_id, create_time, update_time)" +
            "values(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree}," +
            "#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void add(AddStudentDTO addStudentDTO);

    /**
     * 根据id查询学生
     *
     * @param id
     * @return
     */
    @Select("select * from student where id = #{id}")
    StudentVo selectStudentById(Integer id);

    /**
     * 修改学生
     *
     * @param studentVO
     */
    void update(StudentVo studentVO);

    /**
     * 学员违纪扣分
     *
     * @param id
     * @param score
     */
    @Insert("update student set violation_count = violation_count + 1,violation_score = violation_score + #{score} where id = #{id}")
    void updateViolationCountAndScore(Integer id, Integer score);

    /**
     * 批量导入
     *
     * @param students
     */
//    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, " +
//            "degree, graduation_date, clazz_id,violation_count,violation_score, create_time, update_time)"
//            + "values(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree}," +
//            "#{graduationDate},#{clazzId},#{violationCount},#{violationScore},#{createTime},#{updateTime})")
    void batchInsert(List<Student> students,Integer clazzId);

   /**
     * 导出Excel
     * @param clazzId
     * @param name
     * @param degree
     * @return
     */
    List<Student> exportExcel(Integer clazzId,String name,Integer degree);
}
